import org.junit.*;
import java.util.*;
import play.test.*;
import models.*;

public class BasicTest extends UnitTest {

	@Test
	public void createAndRetrieveEntity() {
		EEntity hr = new EEntity("Hr Dep", "Responsible for the employees",
				null).save(); // Create 2 new Entities
		EEntity hr1 = new EEntity("Pr Dep", "Responsible for public relations",
				null).save();

		EEntity hr2 = hr.searchByKeyword("relations").get(0); // Search for
																// entity with
																// "relations"
																// in its
																// decription
		EEntity hr3 = hr.searchByKeyword("Hr Dep").get(0); // Search for entity
															// with "Hr Dep" as
															// its name

		assertNotNull(hr);
		assertNotNull(hr1);
		assertNotNull(hr2);
		assertNotNull(hr3);
		assertEquals("Pr Dep", hr2.name);
		assertEquals("Hr Dep", hr3.name);
	}

	/**
	 * Test: method: List<User> getListOfOrderedUsers()
	 */
	@Test
	public void createAndRetrieveOrderedUser() {
		User islam = new User("islam", "male", "islam", "secret", new Date(),
				"islam.alaarg@gmail.com", "cairo");
		islam.contribution = 1;
		islam.save();
		User omar = new User("omar", "male", "omar", "secret", new Date(),
				"omar@gmail.com", "cairo");
		omar.contribution = 5;
		omar.save();
		User fat7y = new User("fat7y", "male", "fat7y", "secret", new Date(),
				"fat7y@gmail.com", "cairo");
		fat7y.contribution = 3;
		fat7y.save();
		List<User> result = User.getListOfOrderedUsers();
		assertEquals(3, User.count());
		assertNotNull(result.get(2));
		assertEquals(omar, result.get(0));
		assertEquals(fat7y, result.get(1));
		assertEquals(islam, result.get(2));
	}

	@Test
	public void createAndRetrieveUser() {
		User islam = new User("islam", "male", "islam", "secret", new Date(),
				"islam.alaarg@gmail.com", "cairo");
		islam.contribution = 1;
		islam.save();
		User omar = new User("omar", "male", "omar", "secret", new Date(),
				"omar@gmail.com", "cairo");
		omar.contribution = 5;
		omar.save();
		User fat7y = new User("fat7y", "male", "fat7y", "secret", new Date(),
				"fat7y@gmail.com", "cairo");
		fat7y.contribution = 3;
		fat7y.save();
		User result1 = User.getUserInfo("islam");
		User result2 = User.getUserInfo("omar");
		User result3 = User.getUserInfo("fat7y");
		assertEquals("islam", result1.name);
		assertEquals(1, result1.contribution);
		assertEquals("omar", result2.name);
		assertEquals("fat7y", result3.name);
		assertEquals("cairo", result2.address);
	}
}
